package com.atguigu.gmall.product.rest;

import com.atguigu.cache.service.BitmapService;
import com.atguigu.gmall.common.constant.RedisConstant;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.entity.SkuInfo;
import com.atguigu.gmall.model.product.vo.SkuInfoVO;
import com.atguigu.gmall.product.service.SkuInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.lettuce.core.RedisChannelInitializer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product")
public class SkuController {

    @Autowired
    SkuInfoService skuInfoService;
    @Autowired
    BitmapService bitmapService;

    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfoVO skuInfoVO) {
        skuInfoService.saveSkuInfo(skuInfoVO);
        return Result.ok();
    }

    /**
     * /admin/product/list/1/10
     */
    @GetMapping("/list/{page}/{size}")
    public Result list(@PathVariable Long page,@PathVariable Long size) {
        Page<SkuInfo> pageList = skuInfoService.page(new Page<SkuInfo>(page, size));
        return Result.ok(pageList);
    }

    /**
     * 上架
     * @param skuId
     * @return
     */
    @GetMapping("/onSale/{skuId}")
    public Result onSale(@PathVariable Long skuId) {
        skuInfoService.onSale(skuId);
        return Result.ok();
    }

    /**
     * 下架
     * @param skuId
     * @return
     */
    @GetMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable Long skuId) {
        skuInfoService.cancelSale(skuId);
        return Result.ok();
    }


    @GetMapping("/init/bitmap")
    public Result initBitmap() {
        skuInfoService.initBitmap();
        return Result.ok();
    }
}
